package com.library.controller;


import com.library.entity.OaApprove;
import com.library.entity.OaApproveExt;
import com.library.service.OaApproveServiceImpl;
import com.library.vo.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ido
 * @since 2024-12-14
 */
@Controller
public class OaApproveController {

    public static final String prefix = "/api/approve";

    @Autowired
    private OaApproveServiceImpl oaApproveService;

    @RequestMapping(path = prefix + "/list",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult list(@RequestBody OaApprove userInfo) {
        List<OaApproveExt> list = this.oaApproveService.list(userInfo);
        return BaseResult.successWithData(list);
    }

    @RequestMapping("approve.html")
    public ModelAndView allBooks() {
        ArrayList<OaApprove> readers = new ArrayList<>();
        ModelAndView modelAndView = new ModelAndView("approve");
        return modelAndView;
    }

    @RequestMapping(path = prefix + "/add",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult add(@RequestBody OaApprove userInfo ) {
        this.oaApproveService.add(userInfo );
        return BaseResult.success();
    }

    @RequestMapping(path = prefix + "/delete",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult delete(@RequestBody OaApprove userInfo) {
        this.oaApproveService.delete(userInfo);
        return BaseResult.success();
    }

    //同意
    @RequestMapping(path = prefix + "/approve",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult approve(@RequestBody OaApprove userInfo) {
        this.oaApproveService.approve(userInfo);
        return BaseResult.success();
    }

    //驳回
    @RequestMapping(path = prefix + "/reject",
            method = RequestMethod.POST
    )
    @ResponseBody
    public BaseResult reject(@RequestBody OaApprove userInfo) {
        this.oaApproveService.reject(userInfo);
        return BaseResult.success();
    }


//    @RequestMapping(path = prefix + "/update",
//            method = RequestMethod.POST
//    )
//    @ResponseBody
//    public BaseResult update(@RequestBody OaApprove userInfo) {
//        this.oaApproveService.update(userInfo);
//        return BaseResult.success();
//    }

//    @RequestMapping(path = prefix + "/detail",
//            method = RequestMethod.POST
//    )
//    @ResponseBody
//    public BaseResult detail(@RequestBody OaApprove userInfo) {
//        OaApprove userInfo1 = this.oaApproveService.detail(userInfo);
//        return BaseResult.successWithData(userInfo1);
//    }


}
